﻿using System;
using System.Text;

namespace OST.Shared.SharedTypes
{
    /// <summary>
    /// represents the motor-configuration
    /// </summary>
    public class MotorConfiguration
    {        
        #region CTOR

        public MotorConfiguration()
        {
            Class = string.Empty;
            Delay = 5000;
            Wait = 1000;
            Duration = 0;
            Preload = 0;
            OverrunThr = 6;
            Overrun = 5;

        }
        #endregion

        #region Properties

        /// <summary>
        /// class name for used <see cref="IMotor"/> implemention
        /// </summary>
        public string Class { get; set; }

        /// <summary>
        /// endstop-sensor delay, after redriving from there, in ms
        /// </summary>
        public int Delay { get; set; }

        /// <summary>
        /// motor init check cycle-period, in ms
        /// </summary>
        public int Wait { get; set; }

        /// <summary>
        /// motor init check cycle-period, in ms
        /// </summary>
        public int Duration { get; set; }

        /// <summary>
        /// time-preload before a target is driven, in ms
        /// </summary>
        /// <remarks>e.g.: for use of an ntc-element to provide an soft-start</remarks>
        public int Preload { get; set; }

        /// <summary>
        /// motor  overrun stop counter threshold, after that count of stops the 'OverrunError'-Property is added to motor-position
        /// </summary>
        public int OverrunThr { get; set; }

        /// <summary>
        /// OverrunError, in mm
        /// </summary>
        public int Overrun { get; set; }

        #endregion

        #region Methods

        /// <summary>
        /// validates the this instance
        /// </summary>
        public void Validate()
        {
            if (Class == string.Empty)
            {
                throw new OSTException("config-motor: no <Class/> definied");
            }

        }

        public override string ToString()
        {
            var str = new StringBuilder();

            str.AppendLine();
            str.AppendLine("Class: " + Class);
            str.AppendLine("Delay: " + Delay);
            str.AppendLine("Wait: " + Wait);
            str.AppendLine("Duration: " + Duration);
            str.AppendLine("Preload: " + Preload);
            str.AppendLine("OverrunThr: " + OverrunThr);
            str.AppendLine("Overrun: " + Overrun);

            return str.ToString();
        }

        #endregion
    }
}
